<?php

class category_Form_Category extends Zend_Form
{

    protected $_noDecorator = array(
        'ViewHelper', 
        'Errors'
    );	

    public function cluBuild($params)
    //public function init()
    {
        // set the method for the display form to POST
        $this->setMethod('POST');
        
        if($params['formName'] == 'new')
//        {
//	    	$actionNewForm = $params['view']->hvnUrl(array('module' => 'category', 'action'=>'new'), 'nocontroller');
//	        $this->setAction($actionNewForm);
	        $this->setAttrib('id', 'new_category');
//        }
//		elseif($params['formName'] == 'edit')
//		{
//			$actionEdit = $params['view']->hvnUrl(array('module' => 'category', 'action'=>'edit'),'nocontroller');
//	        $this->setAction($actionEdit);
//		}
    	
        $this->setAction($params['action_url']);
		
        $myValidator = new Zend_Validate_Regex('/^[A-Z0-9_\s\-]*$/i'); //alpha, num, space, -, _
        $myValidator->setMessage(__("Only alphanum, spaces, -, _ allowed"), Zend_Validate_Regex::NOT_MATCH);
        $isValidator = new Zend_Validate_Digits();
        $this->addElementPrefixPath('Clu_Filter', 'Clu/Filter/', 'filter');
                
		//add name
		$name = new Zend_Form_Element_Text('name', 
                         array('disableLoadDefaultDecorators' => true,
                               'required' => true,             
                               'class' => 'inputText'));
        
        $name->addDecorators($this->_noDecorator)
        	 ->addValidator($myValidator);
        $this->addElement($name);
        
        //add title
        $title = new Zend_Form_Element_Text('title', 
                         array('disableLoadDefaultDecorators' => true,
                               'required'   => true,             
                               'class' => 'inputText'));
        $title->setAttrib('size', 60) ;
        $title->addDecorators($this->_noDecorator);
        $this->addElement($title);
        
        //add weight
        $weight = new Zend_Form_Element_Text('weight', 
                         array('disableLoadDefaultDecorators' => true,
                               // 'required'   => true
                         ));
        $weight->setAttrib('size', 3) ;
        $weight->addDecorators($this->_noDecorator)
               ->addValidator($isValidator);
        $this->addElement($weight);
        
        //add allow_multiselect
        $allow_multiselect = new Zend_Form_Element_Select('allow_multiselect', 
                         array('disableLoadDefaultDecorators' => true,
                               //'required'   => true
                         	));
		$allow_multiselect->addMultiOption(0,t(132))
               			->addMultiOption(1,t(131))   
               			->addDecorators($this->_noDecorator);
        $this->addElement($allow_multiselect);                      
                         
                         
        //add pid
        $pid = new Zend_Form_Element_Select('pid', 
                         array('disableLoadDefaultDecorators' => true,
                               'required'   => true
								));
        $pid->addMultiOption('0',__('Root'));                 
    	$mCategory = new category_Model_Category();
    	$mCategory->setTables($params['type']);
    	$tmp = $mCategory->getTree(0);
        foreach ($tmp as $c) {
            $pid->addMultiOption($c['id'], $c['displayName']);
        }
        $pid->addDecorators($this->_noDecorator);
        $this->addElement($pid);
		
        //add description
		$description = new Clu_Form_Element_FckEditor('description', array(
        		'fckOptions' => array (
        						'Height' => 600,
        						'Width'  => 600,
        						'ToolbarSet' => 'Full'
        					)
       			 )
        );
        $description->addDecorators($this->_noDecorator);
        	 //->addValidator($isValidator);
        $this->addElement($description);
        
        if($params['formName'] == 'new')
        {
	        // add the submit button
	        $submit = new Zend_Form_Element_Submit('submit', array('disableLoadDefaultDecorators' => true, 
	                                                               'label' => __('Creat') ));
	        $submit->addDecorators($this->_noDecorator);
	        $this->addElement($submit);
        }
        else
        {
        	// add the submit button
	        $submit = new Zend_Form_Element_Submit('submit', array('disableLoadDefaultDecorators' => true, 
	                                                               'label' => __('Update') ));
	        $submit->addDecorators($this->_noDecorator);
	        $this->addElement($submit);
        }
    }
} 
?>
